package com.ytxt.taskdemo.common.config;

//import com.tyyd.configkeeper.client.ConfigListener;
//import com.tyyd.configkeeper.client.ConfigkeeperClients;
//import com.tyyd.configkeeper.client.internal.impl.DefaultConfigManager;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.StringReader;
import java.util.Properties;
import java.util.concurrent.Executor;

/**
 * @author xujunjie xujunjie@189read.com
 * @version V1.0
 * @Title: 配置中心
 * @Package
 * @Description: (用一句话描述该文件做什么)
 * @date
 */
public class TyydConfigurations
{
    private static final Logger logger = LoggerFactory.getLogger(TyydConfigurations.class);

    public static Properties properties;

    private static boolean init = false;

    public TyydConfigurations(String dataId, String group) {
        logger.info("Start to initialization configuration information. dataId:{}, group:{}", dataId, group);
//
//        if(init)
//        {
//            logger.error("End to initialization configuration information. dataId:{}, group:{}", dataId, group);
//            return;
//        }
//
//        DefaultConfigManager mgr = ConfigkeeperClients
//                .createDefaultConfigManager(dataId, group, new ConfigListener() {
//                    public void receiveConfig(String configContent) {
//                        if (StringUtils.isBlank(configContent)) {
//                            return;
//                        }
//                        try {
                            properties = new Properties();
//                            properties.load(new StringReader(configContent));
//                            TyydConfigurations.properties = properties;
//                        } catch (Exception e) {
//                            logger.error("Error to initialization configuration information. Exception message:{}", e.getMessage());
//                        }
//                    }
//
//                    public Executor getExecutor() {
//                        return null;
//                    }
//                });
//        TyydConfigurations.properties = mgr.getConfigureAsProperties();
//
//        if (null != TyydConfigurations.properties) {
//            logger.info("The initialization configuration information is success. dataId:{}, group:{}", dataId, group);
//        }
//
//        init = true;
//        logger.info("Finished to initialization configuration information. dataId:{}, group:{}", dataId, group);
    }
}
